<?php
//$http = new Swoole\http\Server("0.0.0.0", 8090);
//$http->set([
//    'worker_num' => 2
//]);
//$i = 1;
//$http->on('request', function ($request, $response) {
//    global $i;
//    $response->end($i++);
//});
//$http->start();

//TCP服务
//$server = new Swoole\Server("0.0.0.0", 8090);
////监听连接进入事件
//$server->on('Connect', function ($server, $fd) {
//    echo '客户端链接'. PHP_EOL;
//});
////监听数据接收事件
//$server->on('Receive', function ($server, $fd, $reactor_id, $data) {
//    $server->send($fd, "Server: {$data}");
//});
////监听链接关闭时间
//$server->on('Close', function ($server, $fd) {
//    echo '链接关闭'.PHP_EOL;
//});
//$server->start();



//UDP
$server = new Swoole\Server("0.0.0.0", 8090, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
//监听数据接收事件
$server->on('Packet', function ($server, $data, $clientInfo) {
    var_dump($clientInfo);
    $server->sendto($clientInfo['address'], $clientInfo['port'], "Server：{$data}");
});
$server->start();